<template>
  <div id="app">
    <transition name="routerSwitch">
      <router-view/>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'App',
  created:function(){
    let menu = sessionStorage.getItem('menu');
    let token = sessionStorage.getItem('token');
    console.log(token)
    console.log(token == undefined)
    if(token == undefined || token === '' || token == null){
      this.$router.push({path:'/login'})
    }else{
      if(menu && this.$router.options.routes[1].children.length == 0){
        menu = JSON.parse(menu)
      
        for(var i=0;i<menu.length;i++){
                      
            for(var ii=0;ii<menu[i].child.length;ii++){
                let temp = function(j,jj){
                    let obj = {
                            path: menu[j].child[jj].path,
                            name: menu[j].child[jj].pathName,
                            component: function(resolve){
                                require([`@/components/${menu[j].child[jj].compo}`],resolve)
                            }
                        }
                        console.log(menu[j].child[jj].compo);
                    return obj
                    }(i,ii)
                this.$router.options.routes[1].children.push(temp)
            }
        }
        this.$router.addRoutes(this.$router.options.routes);
        this.$router.push({path:'/index',query:{menu:menu}})
      }
    }
    
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

html,body{
  width:100%;
  height:100%;
  margin:0;
  padding:0;
}

html,body #app{
  width:100%;
  height:100%;
}

.routerSwitch-enter-active {
  transition: all .3s ease;
}
.routerSwitch-leave-active {
  transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.routerSwitch-leave-to
  /* .routerSwitch-leave-active for below version 2.1.8 */ {
  transform: translateX(-100%);
  opacity: 0;
}
</style>
